package com.cloudfun.campusshare.util;

import cn.hutool.core.util.NumberUtil;
import org.apache.commons.lang.math.NumberUtils;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

/**
 * @author : zhangyongjie
 * @version : 1.0
 * @createTime : 2020/6/10 10:54
 * @description : 距离计算
 */
public class GeoDisComputeUtil {

    public  static double computeDistance(double lat1, double log1, double lat2, double log2){
//        GlobalCoordinates source = new GlobalCoordinates(31.12055, 121.717594);
//        GlobalCoordinates target = new GlobalCoordinates(31.090867, 121.817629);
        GlobalCoordinates source = new GlobalCoordinates(lat1, log1);
        GlobalCoordinates target = new GlobalCoordinates(lat2, log2);
        return NumberUtil.round(getDistanceMeter(source, target, Ellipsoid.Sphere) / 1000, 2).doubleValue();
    }
    public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo, Ellipsoid ellipsoid)
    {
        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(ellipsoid, gpsFrom, gpsTo);
        return geoCurve.getEllipsoidalDistance();
    }
}
